package com.banyuan;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/*
* 拷贝方法
* IOEexcption要抛出去，由调用的人来普获
* //is,os都由用户自己关
*
*
* */

public class IOUtilis {


    public static void copy(InputStream is,OutputStream os) throws IOException {
        Integer buffSize = 1024 * 1024;
        copy(is,os,buffSize);
    }


    public static void copy(InputStream is ,OutputStream os, Integer buffSize) throws IOException {
    if (is == null || os == null) {
        System.out.println("参数异常");
    }
    if (buffSize <= 0) {
        System.out.println("buffSize要大于0");
    }
    byte[] bytes = new byte[buffSize];
    int len;
    while ((len = is.read(bytes)) > 0) {
        os.write(bytes,0,len);
    }

}


    // 关流方法
    public static void closeQuiety(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }






    public static void closeQuiety(OutputStream os) {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    // 什么都不做，静悄悄的关闭closeQuitely
                }
            }
        }
    public static void closeQuiety(InputStream is) {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

